<?php
use com\mostka\serializer\BadPrimitiveTypeException;
use com\mostka\serializer\Serializer;

/**
 * Created by PhpStorm.
 * User: Jozef Môstka
 * Date: 5/25/14
 * Time: 7:23 PM
 */

class TestObjectGenerated extends TestObject{

    /**
     * @param $___serializer Serializer
     * @param TestObject[] $___testObject
     */
    public static function ___serializeArr($___serializer, $___testObject){
        $___serializer->writeByte(Serializer::OBJECT_ARR);
        if ($___testObject==null){
            $___serializer->writeInteger(-1);
            return;
        }
        $___serializer->writeInteger(count($___testObject));
        foreach($___testObject as $t){
            /** @var TestObject $t */
            self::___serialize($___serializer,$t);
        }
	}

    /**
     * @param Serializer $___serializer
     * @param TestObject $___testObject
     */
    public static function ___serialize( $___serializer,  $___testObject){
        $___serializer->writeByte(Serializer::OBJECT);

        $___serializer->writeBoolean($___testObject==null);
        if ($___testObject==null){
            return;
        }

        $___serializer->writeStringArr($___testObject->aaa);
        $___serializer->writeIntegerArr($___testObject->bbb);
        $___serializer->writeDoubleArr($___testObject->ccc);
        $___serializer->writeCharArr($___testObject->ddd);
        $___serializer->writeLongArr($___testObject->eee);
        $___serializer->writeByteArr($___testObject->fff);
        $___serializer->writeShortArr($___testObject->ggg);
        $___serializer->writeBooleanArr($___testObject->hhh);
        TestObjectGenerated::___serializeArr($___serializer,$___testObject->object);
        TestObject2Generated::___serializeArr($___serializer, $___testObject->object2);
        $___serializer->writeString($___testObject->iii);
    }

    /**
     * @param Serializer $___serializer
     * @return null|\TestObject[]
     * @throws BadPrimitiveTypeException
     */
    public static function ___deserialize($___serializer){
        $___serializer->checkType(Serializer::OBJECT);
        if ($___serializer->readBoolean()){
            return null;
        }
        $___testObject = new TestObject();
		$___testObject->aaa = $___serializer->readStringArr();
		$___testObject->bbb = $___serializer->readIntegerArr();
		$___testObject->ccc = $___serializer->readDoubleArr();
		$___testObject->ddd = $___serializer->readCharArr();
		$___testObject->eee = $___serializer->readLongArr();
		$___testObject->fff = $___serializer->readByteArray();
		$___testObject->ggg = $___serializer->readShortArr();
		$___testObject->hhh = $___serializer->readBooleanArr();
		$___testObject->object = TestObjectGenerated::___deserializeArr($___serializer);
		$___testObject->object2 = TestObject2Generated::___deserializeArr($___serializer);
		$___testObject->iii = $___serializer->readString();
		
		return $___testObject;
	}

    /**
     * @param Serializer $___serializer
     * @return TestObject[]|null
     * @throws BadPrimitiveTypeException
     */
    public static function ___deserializeArr($___serializer){
        $___serializer->checkType(Serializer::OBJECT_ARR);
        $___len = $___serializer->readInteger();
		if ($___len==-1){
            return null;
        }
        /** @var TestObject[] $___len */
		$___ret = array();
		for($___i=0;$___i<$___len;$___i++){
            $___ret[$___i]=TestObjectGenerated::___deserialize($___serializer);
		}
		return $___ret;
	}
} 